#coding=utf-8
import random
import time

skls= ["\033[32m<R>哉佩利敖光线\033[0m","\033[34m<SR>须佐能乎\033[0m",
       "\033[32m<R>十万伏特\033[0m","\033[32m<R>焰分噬浪尺\033[0m",
       "\033[34m<SR>我眼即你眼\033[0m","\033[34m<SR>雷切\033[0m",
       "\033[32m<N>回复\033[0m","\033[34m<SR>无下限术式\033[0m",
       "\033[32m<R>超电磁炮\033[0m","\033[34m<SR>咒力拳\033[0m"
       ]
skiwt=[1,  0.6,  
       1,  1,  
       0.6,  0.4,  
       0.9,  0.4,  
       1,  0.5  
       ]
tls=["\033[32m<平凡>狂暴\033[0m","\033[32m<平凡>灵巧\033[0m","\033[32m<平凡>盾山\033[0m","\033[32m<平凡>铁腕\033[0m"]
tlsid=[0,1,2,3]
tlwt=[1,1,1,1]
tlexps=["额外伤害","闪避概率增加","被暴击时部分伤害减免","额外生命值"]
xuzuoa=False
zaiyana=False
wuxiana=False
xuzuob=False
zaiyanb=False
wuxianb=False
zhoulia=-10
zhoulib=-10
tmpatka=0
tmpatkb=0

totalAttacka=0
totalAttackb=0
totalTreatmenta=0
totalTreatmentb=0
cnt=0
add=0
adda=0
addb=0
pointa=0
pointb=0
ifGameEnds=False

#############################################定义随机函数
def doRandint(sd,bg,ed,c):

    random.seed(sd*c+time.time())
    return random.randint(bg,ed)

def doRandomChoice(sd,lst,c):

    random.seed(sd*c+time.time())
    return random.choice(lst)

def doRandomHide(sd,c):

    random.seed(sd*c+time.time())
    return random.randint(1,10)

def doUniqueRandom(sd,bg,ed):

    tmp=sd*sd-12
    random.seed(tmp)
    return random.randint(bg,ed)

def doRandomChoices(sd,lst,weights):

    random.seed(sd)
    return random.choices(lst,weights)[0]

def getRandomSeed(string,key):

    length=len(string)
    num=0
    for i in range(length):
        code=ord(string[i])*(i+1)
        num+=code*(key*2-1)
    return num


#############################################输入

nma=""
rda=0
nmb=""
rdb=0
nma=str(input("请输入名字1:  "))
rda=getRandomSeed(nma,1)
#print("<调试> "+nma+"的随机种子是："+str(rda))
nmb=str(input("请输入名字2:  "))
rdb=getRandomSeed(nmb,1)
#print("<调试> "+nmb+"的随机种子是："+str(rdb))


#############################################各数值初始化处

print("战斗开始中，请稍等......")
time.sleep(1)

tlfa=doRandomChoices(rda,tlsid,tlwt)
tlfb=doRandomChoices(rdb,tlsid,tlwt)
print("===天赋初始化完成===")
time.sleep(0.5)
print(nma+"的天赋为： "+tls[tlfa])
time.sleep(0.1)
print("效果："+tlexps[tlfa])
time.sleep(0.5)
print(nmb+"的天赋为： "+tls[tlfb])
time.sleep(0.1)
print("效果："+tlexps[tlfb])
time.sleep(1)

lfa=doUniqueRandom(rda,100,200)
random.seed(rdb)
lfb=doUniqueRandom(rdb,100,200)
print("===血量初始化完成===")
if tlfa==3:
    adda=random.randint(10,30)
    print(nma+"的初始血量为： "+str(lfa)+"+"+str(adda))
    lfa+=adda
else:
    print(nma+"的初始血量为： "+str(lfa))
time.sleep(0.5)
if tlfb==3:
    addb=random.randint(10,30)
    print(nmb+"的初始血量为： "+str(lfb)+"+"+str(addb))
    lfb+=addb
else:
    print(nmb+"的初始血量为： "+str(lfb))

time.sleep(1)

print("")
start="==================战斗开始=================="
print(f"\033[31m{start}\033[0m")
print("")


#############################################主体
    
for i in range(100):

    time.sleep(1)
    tmplfa=lfa
    tmplfb=lfb
    out=""

    #随机技能与攻击力
    skla=doRandomChoices(rda+time.time()+cnt,skls,skiwt)
    cnt+=1
    if (skla=="\033[34m<SR>须佐能乎\033[0m" and xuzuoa==True) or (skla=="\033[34m<SR>我眼即你眼\033[0m" and zaiyana==True) or (skla=="\033[34m<SR>无下限术式\033[0m" and zaiyana==True):
        while not(skla!="\033[34m<SR>须佐能乎\033[0m" and skla!="\033[34m<SR>我眼即你眼\033[0m" and skla!="\033[34m<SR>无下限术式\033[0m"):
            skla=doRandomChoices(rda+time.time()+cnt,skls,skiwt)
            cnt+=1

    atka=doRandint(rda,10,60,cnt)
    cnt+=1

    print(" ")
    print("        =========第"+str(i+1)+"回合开始=========")

    #轮到A攻击的回合
    if skla=="\033[34m<SR>须佐能乎\033[0m":
        out=nma+"使用了"+skla+",下一次攻击必定暴击！"
        print(f"{out}")
        xuzuoa=True

    elif skla=="\033[34m<SR>我眼即你眼\033[0m":
        out=nma+"使用了"+skla+"给予了"+nmb+"一个致盲效果，他下回的攻击会被闪避！"
        print(f"{out}")
        zaiyana=True

    elif skla=="\033[32m<N>回复\033[0m":
        out=nma+"使用了"+skla+"，恢复了"+str(atka)+"点血量"
        print(f"{out}")
        lfa+=atka
        totalTreatmenta+=atka

    elif skla=="\033[34m<SR>无下限术式\033[0m":
        out=nma+"使用了"+skla+"，下回"+nmb+"的攻对他无效！"
        print(f"{out}")
        wuxiana=True

    elif skla=="\033[34m<SR>雷切\033[0m":
        wuxianb=False
        zaiyanb=False
        if tlfa==0:
            out=nma+"使用了"+skla+"，无视"+nmb+"的天赋，无法减伤或躲避!"+"打出了"+str(atka)+"+"+str(add)+"点伤害"
            print(f"{out}")
            add=doRandint(rda,1,10,time.time())
            atka+=add
        else:
            out=nma+"使用了"+skla+"，无视"+nmb+"的天赋，无法减伤或躲避!"+"打出了"+str(atka)+"点伤害"
            print(f"{out}")
        pointa+=int(atka/10)
        lfb-=atka
        print(nmb+"受到了"+str(atka)+"点伤害")

    else:
        if tlfa==0:
            add=doRandint(rda,1,10,time.time())
            print(nma+"使用了"+skla+"，打出了"+str(atka)+"+"+str(add)+"点伤害")
            atka+=add
        else:
            print(nma+"使用了"+skla+"，打出了"+str(atka)+"点伤害")

        time.sleep(0.5)
        hdb=doRandomHide(rdb,cnt)
        cnt+=1

        if xuzuoa:
            if tlfb==2:
                add=doRandint(rdb,5,20,time.time())
                out="由于"+nma+"使用了\033[34m<SR>须佐能乎\033[0m，"+nmb+"直接受到了暴击，承受了"+str(atka*2)+"-"+str(add)+"点伤害"
                print(f"{out}")
                lfb-=atka*2+add
                pointb+=int((atka*2+add)/10)
            else:
                out="由于"+nma+"使用了\033[34m<SR>须佐能乎\033[0m，"+nmb+"直接受到了暴击，承受了"+str(atka*2)+"点伤害"
                print(f"{out}")
                lfb-=atka*2
                pointb+=int((atka*2)/10)
            xuzuoa=False

        elif zaiyanb:
            out="由于"+nmb+"使用了\033[34m<SR>我眼即你眼\033[0m，"+nmb+"闪避成功，只承受了"+str(atka/2)+"点伤害"
            print(f"{out}")
            lfb-=atka/2
            pointb+=int(atka/20)
            zaiyanb=False

        elif wuxianb:
            print("但是由于"+nmb+"使用了\033[34m<SR>无下限术式\033[0m，所以本次攻击不奏效！")
            wuxianb=False

        else:
            nbrdm=doRandint(time.time(),1,15,cnt)
            cnt+=1
            if nbrdm==7:
                out=nmb+"直接反弹，使"+nma+"受到了"+str(atka-10)+"点伤害！"
                lfa-=atka-10
                pointa+=int((atka-10)/10)
                print(f"\033[36m{out}\033[0m")

            elif 1<=rdb and 3>=rdb:
                tri=random.randint(1,5)
                if tlfb==1 and tri==3:
                    out=nmb+"灵巧地躲过了暴击，只承受了"+str(atka)+"点伤害"
                    print(f"\033[30m{out}\033[0m")
                    lfb-=atka
                    pointb+=int(atka/10)
                else:
                    if tlfb==2:
                        add=doRandint(rdb,5,20,time.time())
                        out=nmb+"躲闪不及，受到了暴击，承受了"+str(atka*2)+"-"+str(add)+"点伤害"
                        print(f"\033[31m{out}\033[0m")
                        lfb-=atka*2+add
                        pointb+=int((atka*2+add)/10)
                    else:
                        out=nmb+"躲闪不及，受到了暴击，承受了"+str(atka*2)+"点伤害"
                        print(f"\033[31m{out}\033[0m")
                        lfb-=atka*2
                        pointb+=int((atka*2)/10)

            elif 8<=rdb and 10>=rdb:
                out=nmb+"闪避成功，只承受了"+str(atka/2)+"点伤害"
                print(f"\033[30m{out}\033[0m")
                lfb-=atka/2
                pointb+=int(atka/20)

            else:
                tri=random.randint(1,5)
                if tlfb==1 and tri==3:
                    out=nmb+"灵巧地躲过了攻击，只承受了"+str(atka/2)+"点伤害"
                    print(f"\033[30m{out}\033[0m")
                    lfb-=atka/2
                    pointa+=int(atka/20)
                else:
                    print(nmb+"受到了"+str(atka)+"点伤害")
                    lfb-=atka
                    pointa+=int(atka/10)

    time.sleep(1)

    #统计数据
    if(tmplfb-lfb>0):
        totalAttacka+=tmplfb-lfb
    if(tmplfa-lfa>0):
        totalAttackb+=tmplfa-lfa

    #判断是否有一方倒下
    if(lfa<=0):
        print(" ")
        print(" ")
        print(" ")
        print("==================战斗结束，"+nmb+"胜利！！==================")
        print("剩余血量："+str(lfb))
        ifGameEnds=True
        break
    if(lfb<=0):
        print(" ")
        print(" ")
        print(" ")
        print("==================战斗结束，"+nma+"胜利！！==================")
        print(">>>剩余血量："+str(lfa))
        ifGameEnds=True
        break

    #随机技能与攻击力
    sklb=doRandomChoices(rdb+time.time()+cnt,skls,skiwt)
    cnt+=1
    if (sklb=="\033[34m<SR>须佐能乎\033[0m" and xuzuob==True) or (sklb=="\033[34m<SR>我眼即你眼\033[0m" and zaiyanb==True) or (sklb=="\033[34m<SR>无下限术式\033[0m" and zaiyanb==True):
        while not(sklb!="\033[34m<SR>须佐能乎\033[0m" and sklb!="\033[34m<SR>我眼即你眼\033[0m" and sklb!="\033[34m<SR>无下限术式\033[0m"):
            sklb=doRandomChoices(rdb+time.time()+cnt,skls,skiwt)
            cnt+=1

    atkb=doRandint(rdb,10,60,cnt)
    cnt+=1

    #轮到B攻击的回合    
    if sklb=="\033[34m<SR>须佐能乎\033[0m":
        out=nmb+"使用了"+sklb+"，下一次攻击必定暴击！"
        print(f"{out}")
        xuzuob=True

    elif sklb=="\033[34m<SR>我眼即你眼\033[0m":
        out=nmb+"使用了"+sklb+"，给予了"+nma+"一个致盲效果，他下回的攻击会被闪避！"
        print(f"{out}")
        zaiyanb=True

    elif sklb=="\033[32m<N>回复\033[0m":
        out=nmb+"使用了"+sklb+"，恢复了"+str(atkb)+"点血量"
        print(f"\033[32m{out}\033[0m")
        lfb+=atkb
        totalTreatmentb+=atkb

    elif sklb=="\033[34m<SR>无下限术式\033[0m":
        out=nmb+"使用了"+sklb+"，下回"+nma+"的攻对他无效！"
        print(f"{out}")
        wuxianb=True

    elif sklb=="\033[34m<SR>雷切\033[0m":
        wuxiana=False
        zaiyana=False
        if tlfb==0:
            out=nmb+"使用了"+sklb+"，无视"+nma+"的任何天赋与防御，无法减伤或躲避!"+"打出了"+str(atkb)+"+"+str(add)+"点伤害"
            print(f"{out}")
            add=doRandint(rdb,1,10,time.time())
            atkb+=add
        else:
            out=nmb+"使用了"+sklb+"，无视"+nma+"的任何天赋与防御，无法减伤或躲避!"+"打出了"+str(atkb)+"点伤害"
            print(f"{out}")
        lfa-=atkb
        pointa+=int(atkb/10)
        print(nma+"受到了"+str(atkb)+"点伤害")

    else:
        if tlfb==0:
            add=doRandint(rda,1,10,time.time())
            print(nmb+"使用了"+sklb+"，打出了"+str(atkb)+"+"+str(add)+"点伤害")
            atkb+=add
        else:
            print(nmb+"使用了"+sklb+"，打出了"+str(atkb)+"点伤害")

        time.sleep(0.5)
        hda=doRandomHide(rda,cnt)
        cnt+=1

        if xuzuob:
            if tlfa==2:
                add=doRandint(rdb,5,20,time.time())
                out="由于"+nmb+"使用了\033[34m<SR>须佐能乎\033[0m，"+nma+"直接受到了暴击，承受了"+str(atkb*2)+"-"+str(add)+"点伤害"
                print(f"{out}")
                lfa-=atkb*2+add
                pointa+=int((atkb*2+add)/10)
            else:
                out="由于"+nmb+"使用了\033[34m<SR>须佐能乎\033[0m，"+nma+"直接受到了暴击，承受了"+str(atkb*2)+"点伤害"
                print(f"{out}")
                lfa-=atkb*2
                pointa+=int((atkb*2)/10)

            xuzuob=False

        elif zaiyana:
            out="由于"+nma+"使用了\033[34m<SR>我眼即你眼\033[0m，"+nma+"闪避成功，只承受了"+str(atkb/2)+"点伤害"
            print(f"{out}")
            lfa-=atkb/2
            pointa+=int(atkb/20)
            zaiyana=False

        elif wuxiana:
            print("但是由于"+nma+"使用了\033[34m<SR>无下限术式\033[0m，所以本次攻击不奏效！")
            wuxiana=False

        else:
            nbrdm=doRandint(time.time(),1,15,cnt)
            cnt+=7
            if nbrdm==20:
                out=nma+"直接反弹，使"+nmb+"受到了"+str(atkb-10)+"点伤害！"
                lfb-=atkb-10
                pointb+=int((atkb-10)/10)
                print(f"\033[36m{out}\033[0m")

            elif 1<=rda and 3>=rda:
                tri=random.randint(1,5)
                if tlfa==1 and tri==3:
                    out=nma+"灵巧地躲过了暴击，只承受了"+str(atkb)+"点伤害"
                    print(f"\033[30m{out}\033[0m")
                    lfa-=atkb
                    pointa+=int((atkb)/10)
                else:

                    if tlfa==2:
                        add=doRandint(rda,5,20,time.time())
                        out=nma+"躲闪不及，受到了暴击，承受了"+str(atkb*2)+"-"+str(add)+"点伤害"
                        print(f"\033[31m{out}\033[0m")
                        lfa-=atkb*2+add
                        pointa+=int((atkb*2+add)/10)
                    else:
                        out=nma+"躲闪不及，受到了暴击，承受了"+str(atkb*2)+"点伤害"
                        print(f"\033[31m{out}\033[0m")
                        lfa-=atkb*2
                        pointa+=int((atkb*2)/10)

            elif 7<=rda and 10>=rda:
                out=nma+"闪避成功，只承受了"+str(atkb/2)+"点伤害"
                print(f"\033[30m{out}\033[0m")
                lfa-=atkb/2
                pointa+=int(atkb/20)

            else:
                tri=random.randint(1,5)
                if tlfa==1 and tri==3:
                    out=nma+"灵巧地躲过了攻击，只承受了"+str(atkb/2)+"点伤害"
                    print(f"\033[30m{out}\033[0m")
                    lfa-=atkb/2
                    pointa+=int(atkb/20)
                else:
                    print(nma+"受到了"+str(atkb)+"点伤害")
                    lfa-=atkb
                    pointa+=int(atkb/10)

    time.sleep(1)

    #恩赐与诅咒判定
    if((i+1)%5==0): #恩赐
        add=doRandint(time.time(),20,50,cnt)
        cnt+=1
        nid=doRandint(time.time(),0,1,cnt)
        cnt+=1
        if bool(nid):
            print("本回合触发了\033[32m<凡阶>天使的恩赐\033[30m,"+nma+"血量回复"+str(add)+"点")
            lfa+=add
        else:
            print("本回合触发了\033[32m<凡阶>天使的恩赐\033[30m,"+nma+"血量回复"+str(add)+"点")
            lfb+=add

    if((i+1)%7==0): #诅咒
        add=doRandint(time.time(),20,50,cnt)
        cnt+=1
        nid=doRandint(time.time(),0,1,cnt)
        cnt+=1
        if bool(nid):
            print("本回合触发了\033[32m<凡阶>恶魔的诅咒\033[30m,"+nma+"血量扣除"+str(add)+"点")
            lfa-=add
        else:
            print("本回合触发了\033[32m<凡阶>恶魔的诅咒\033[30m,"+nma+"血量扣除"+str(add)+"点")
            lfb-=add

    if skla=="\033[34m<SR>咒力拳\033[0m":
            zhoulia=i+1
            tmpatka=atka
    if sklb=="\033[34m<SR>咒力拳\033[0m":
            zhoulib=i+1
            tmpatkb=atkb
    if zhoulia==i:
        print(nmb+"受到"+nma+"的延迟咒力伤害"+str(int(tmpatka*1.2))+"点")
        lfb-=int(tmpatka*1.2)
    if zhoulib==i:
        print(nma+"受到"+nmb+"的延迟咒力伤害"+str(int(tmpatkb*1.2))+"点")
        lfa-=int(tmpatkb*1.2)
    #结算本回合
    print("        =========第"+str(i+1)+"回合结束=========")
    print(" ")

    #判断是否有一方倒下
    if(lfa<=0):
        print(" ")
        print(" ")
        print(" ")
        out="==================战斗结束，"+nmb+"胜利！！=================="
        print(f"\033[33m{out}\033[0m")
        print("                  剩余血量："+str(lfb))
        ifGameEnds=True
        break

    if(lfb<=0):
        print(" ")
        print(" ")
        print(" ")
        out="==================战斗结束，"+nma+"胜利！！=================="
        print(f"\033[33m{out}\033[0m")
        print("                  剩余血量："+str(lfa))
        ifGameEnds=True
        break
    
    #统计数据
    if(tmplfb-lfb>0):
        totalAttacka+=tmplfb-lfb
    if(tmplfa-lfa>0):
        totalAttackb+=tmplfa-lfa
    time.sleep(0.5)
    print(nma+"剩余血量："+str(lfa))
    print(nmb+"剩余血量："+str(lfb))
    print(nma+"目前点数："+str(pointa))
    print(nmb+"目前点数："+str(pointb))

if not ifGameEnds:
    out="==================你们已经大战100回合，还未分出胜负，所以平局=================="
    print(f"\033[33m{out}\033[0m")


#############################################结算画面

print(" ")
print("\033[36m结算中......\033[0m")
print(" ")
time.sleep(3)
print(nma+"总治疗量："+str(totalTreatmenta))
print(nmb+"总治疗量："+str(totalTreatmentb))
print(nma+"总受到伤害："+str(totalAttackb))
print(nmb+"总受到伤害："+str(totalAttacka))
print("总回合数:"+str(i+1))
print(" ")
